home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / qbser310.zip / OFFHOOK.BAS < prev    next >
BASIC Source File  |  1993-04-11  |  4KB  |  146 lines

  1.     DEFINT A-Z
  2.  
  3.     DECLARE SUB Response ()
  4.     DECLARE FUNCTION Value% (Char$)
  5.  
  6. '   This example program is used to take the modem OFF-HOOK and leave it that
  7. '   way. This program was designed to work with a PCBoard BBS system and
  8. '   the port (and perhaps IRQ) information is retrieved from a system file
  9. '   called PCBOARD.DAT. In order to experiment with this program in a
  10. '   non-PCBoard environment, simply remove the lines marked "NO PCBOARD START"
  11. '   until "NO PCBOARD END". Then Add the following variables before the
  12. '   OpenComm statement:
  13. '
  14. '   Port        The port number (1, 2, 3, 4, or any other address)
  15. '   Rate&       The baud rate you want to use (2400, 9600, etc)
  16. '   OffHook$    A string with your modem's off hook command (ATH1)
  17.  
  18. '   $INCLUDE: 'QBSERIAL.DEC'
  19.  
  20.     CLS
  21.     IRQ = 0
  22.     PRINT "Modem OFFHOOK, ver 1.1"
  23.     PRINT
  24.  
  25. ' Print Driver Copyright
  26.  
  27.     X& = DriverCopyright
  28.     WHILE (PEEK(X&))
  29.         CP$ = CP$ + CHR$(PEEK(X&))
  30.         X& = X& + 1
  31.     WEND
  32.     PRINT CP$
  33.     PRINT
  34.  
  35. '----------NO PCBOARD START--------------------------------------------------
  36.     IF DIR$("PCBOARD.DAT") <> "" THEN
  37.         OPEN "PCBOARD.DAT" FOR INPUT AS #1
  38.     ELSE
  39.         Fi$ = COMMAND$
  40.         IF DIR$(Fi$) = "" OR Fi$ = "" THEN
  41.             PRINT "PCBOARD.DAT not found. Check file existance or path spec"
  42.             END
  43.         END IF
  44.         OPEN Fi$ FOR INPUT AS #1
  45.     END IF
  46.  
  47.     IRQ = 0
  48.  
  49.     FOR Lp = 1 TO 52
  50.         INPUT #1, Port$
  51.     NEXT
  52.     INPUT #1, Speed$            'Get Port Speed from PCBOARD.DAT
  53.     INPUT #1, X$
  54.     INPUT #1, X$
  55.     INPUT #1, OffHook$          'Get OFF-HOOK string from PCBOARD.DAT
  56.     Rate& = VAL(Speed$)
  57.     IF Port$ = "NONE" THEN
  58.         PRINT "No Modem."
  59.         END
  60.     END IF
  61.     Port = VAL(MID$(Port$, 4))      'Get port used
  62.     IF Port > 2 THEN                'If port isnt 1 or 2, then you need IRQ
  63.         SEEK #1, 1                  'and Base Address
  64.         FOR Lp = 1 TO 159
  65.             INPUT #1, IRQ$          'get IRQ
  66.         NEXT
  67.         INPUT #1, Port$             'get BASE ADDRESS of port
  68.  
  69.         ' Convert (ascii) HEX value of port to useable decimal value
  70.  
  71.         Port = (Value(MID$(Port$, 1, 1)) * 256) + (Value(MID$(Port$, 2, 1)) * 16) + Value(MID$(Port$, 3, 1))
  72.         IRQ = VAL(IRQ$)
  73.     END IF
  74. '----------NO PCBOARD END----------------------------------------------------
  75.  
  76.     CRLF$ = CHR$(13) + CHR$(10)
  77.     Length = 8
  78.     Parity = 0
  79.     HS = 0
  80.  
  81.     OpenComm Port, IRQ, Length, Parity, Rate&, HS, 0
  82.  
  83.     CarrierDetect 0     ' <-- NEEDED TO TALK TO MODEM W/NO CARRIER!!
  84.  
  85.     ClearInputBuffer
  86.     transmit "AT" + CRLF$
  87.     PRINT "Transmitting: AT"
  88.     Response
  89.     PRINT
  90.  
  91. '    SLEEP 1
  92.  
  93.     ClearInputBuffer
  94.     transmit "AT" + CRLF$
  95.     PRINT
  96.     PRINT "Transmitting: AT"
  97.     Response
  98.     PRINT
  99.  
  100. '    SLEEP 1
  101.  
  102.     ClearInputBuffer
  103.     transmit OffHook$ + CRLF$
  104.     PRINT
  105.     PRINT "Transmitting: " + OffHook$
  106.     Response
  107.     PRINT
  108.  
  109. '    SLEEP 2
  110.  
  111.     DTRcontrol 1            ' DONT turn off DTR, doing so may let modem
  112.                             ' hang up, and we dont want this to happen
  113.     CloseComm
  114.  
  115.     END
  116.  
  117. ' Read data comming from the modem. SUB will not return until an OK is
  118. ' detected. SUB will time-out if an OK is not detected in 4 seconds.                                                
  119. SUB Response
  120.     Start! = TIMER
  121.     PRINT "Response: ";
  122.     I$ = ""
  123.     DO
  124.         IF DataWaiting THEN
  125.             X$ = CHR$(ReadChar)
  126.             PRINT X$;
  127.             I$ = I$ + X$
  128.         END IF
  129.         IF TIMER - Start! > 4 THEN
  130.             PRINT "COMMUNICATIONS TIMEOUT!!"
  131.             EXIT DO
  132.         END IF
  133.     LOOP UNTIL INSTR(I$, "OK")
  134. END SUB
  135.  
  136. FUNCTION Value (Char$)
  137.     SELECT CASE Char$
  138.         CASE "0" TO "9"
  139.             Value = VAL(Char$)
  140.             EXIT FUNCTION
  141.         CASE "A" TO "F"
  142.             Value = ASC(Char$) - 55
  143.     END SELECT
  144. END FUNCTION
  145.  
  146.